** Table C5 subdistrict

********************************* CALLS *********************************************

use "$data/calls_subdistrict_input.dta", replace

encode district_MCA, g(district_MCA_s)
encode state_MCA, g(state_MCA_s)
encode tahsil_code, g(tahsil_code_s)

egen t = group(year)

gen post = (year > 2007)

gen lang_control_post = lang_control * post
label var lang_control_post "Lang Control * Post"

	
reghdfe calls_all_per100C lang_control_post c.share_off_speakers#i.t if in_hyv [aw=area_km2]  , a(tahsil_code_s i.district_MCA_s##i.t  i.subdist_border_id##i.t c.crop_share_fao##i.t c.agri_workers_main##i.t ) cluster(tahsil_code_s)



local replace replace 
foreach c in calls_all_per100C {
	foreach control in "i.district_MCA_s##i.t c.crop_share_fao##i.t c.agri_workers_main##i.t " {
		
		sum `c'
		local control_mean = round(`r(mean)', 0.001)
		
	if strpos("`control'", "i.district_MCA_s##i.t") {
		local dt "Y"
	}
	else {
		local dt "N"
	}
	
	if strpos("`control'", "i.state_MCA_s##i.t") {
		local st "Y"
	}
	else {
		local st "N"
	}
	
	if strpos("`control'", "pct_irrigated") {
		local cc "Y" 
	}
	else {
		local cc "N"
	}
	
	reghdfe `c' lang_control_post c.share_off_speakers#i.t if in_hyv_sample [aw=area_km2] , a(i.tahsil_code_s i.subdist_border_id##i.t `control') cluster(tahsil_code_s)
	
	outreg2 using "$results/tables/table_C5_panelB.tex", tex(frag) dec(3) bracket label keep(lang_control_post) addtext(Pre-Period Mean, "`control_mean'", Subdistrict f.e., Yes, Crop Share * Time f.e., Yes , Subdistirct border * Time f.e., Yes, District * Time f.e., Yes, Census controls * Time FE, Yes) nocons  nonotes `replace'
	
	local replace append 
	
	}
}

************************************	TECH ADOPTION	********************************	

use "$data/tech_subdistrict_input.dta", clear

egen t = group(year)
gen post = (year > 2007)

gen lang_control_post = lang_control * post
label var lang_control_post "Lang Control * Post"

encode district_MCA, g(district_MCA_s)
encode state_MCA, g(state_MCA_s)
encode tahsil_code, g(tahsil_code_s)

label var hyv_share "HYV Share"

local replace append 

foreach c in hyv_share {
	foreach control in "i.district_MCA_s##i.t c.crop_share_fao##i.t c.agri_workers_main##i.t " {
		
		sum `c' [aw = pop2001] if post == 0
		local control_mean = round(`r(mean)', 0.001)
		
	if strpos("`control'", "i.district_MCA_s##i.t") {
		local dt "Y"
	}
	else {
		local dt "N"
	}
	
	if strpos("`control'", "i.state_MCA_s##i.t") {
		local st "Y"
	}
	else {
		local st "N"
	}
	
	if strpos("`control'", "pct_irrigated") {
		local cc "Y" 
	}
	else {
		local cc "N"
	}
	
	reghdfe `c' lang_control_post c.share_off_speakers#i.t if in_hyv_sample [aw = pop2001], a(i.tahsil_code_s i.subdist_border_id##i.t `control' ) cluster(tahsil_code_s)
	
	sleep 1000
	
	outreg2 using "$results/tables/table_C5_panelB.tex", tex(frag) dec(3) bracket label keep(lang_control_post) addtext(Pre-Period Mean, "`control_mean'", Subdistrict f.e., Yes, Crop Share * Time f.e., Yes , Subdistirct border * Time f.e., Yes, District * Time f.e., Yes, Census controls * Time FE, Yes) nocons  nonotes `replace'
	
	local replace append 
	
	}
}


************************************	YIELD	********************************	
use "$data/yield_subdistrict_input.dta", clear

egen t = group(year)
gen post = (year > 2007)

gen lang_control_post = lang_control * post
label var lang_control_post "Non-state official language speakers (%) * Post"

encode district_MCA, g(district_MCA_s)
encode state_MCA, g(state_MCA_s)
encode tahsil_code, g(tahsil_code_s)

label var total_yield_sdt "Yield"


local replace append 

foreach c in total_yield_sdt {
	foreach control in "i.district_MCA_s##i.t c.crop_share_fao##i.t c.agri_workers_main##i.t " {
		
		sum `c' [aw = pop2001] if post == 0
		local control_mean = round(`r(mean)', 0.001)
		
	if strpos("`control'", "i.district_MCA_s##i.t") {
		local dt "Y"
	}
	else {
		local dt "N"
	}
	
	if strpos("`control'", "i.state_MCA_s##i.t") {
		local st "Y"
	}
	else {
		local st "N"
	}
	
	if strpos("`control'", "pct_irrigated") {
		local cc "Y" 
	}
	else {
		local cc "N"
	}
	
	reghdfe `c' lang_control_post c.share_off_speakers#i.t if in_hyv_sample [aw = pop2001], a(i.tahsil_code_s i.subdist_border_id##i.t `control' ) cluster(tahsil_code_s)
	
	sleep 1000
	
	outreg2 using "$results/tables/table_C5_panelB.tex", tex(frag) dec(3) bracket label keep(lang_control_post) addtext(Pre-Period Mean, "`control_mean'", Subdistrict f.e., Yes, Crop Share * Time f.e., Yes , Subdistirct border * Time f.e., Yes, District * Time f.e., Yes, Census controls * Time FE, Yes) nocons  nonotes `replace'
	
	local replace append 
	
	}
}
